/*
	This file is part of AVRCppLib.

    AVRCppLib is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    AVRCppLib is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with AVRCppLib.  If not, see <http://www.gnu.org/licenses/>.

    Copyright (C) Maxime Lemonnier 2007-2011
 */

#ifndef ENUM_H_
#define ENUM_H_
#include "Utils.h"





/*!
 * Enum base class, meant to reproduce Java's Enum type behaviour
 *
 */
template<class ValueType>
class Enum {
public:

/*!
 * Getter for this Enum's instance value
 * @return this Enum's instance value
 */
	ValueType getConstant() const{return constant;}

	bool operator==(const Enum<uint8_t>  & rhs)
	{
		return (this->constant == rhs.constant);
	}
protected:
	/*!
	 * Protected default constructor (to prevent usage)
	 */
	Enum(): constant(0){};

	/*!
	 * Protected constructor (to prevent usgae)
	 * @param constant this Enum's instance value
	 */
	Enum(ValueType constant) : constant(constant){}
private:
	ValueType constant;
};

typedef Enum<uint8_t> Enum8u;


class Prescaler : public Enum8u
{
public:

	uintmax_t toHertz() const
	{
		return clockSource / prescaler;
	}

	double toSeconds() const
	{
		return 1.0 / (double)(toHertz());
	}
protected:
	/*!
	 * @overload
	 */
	Prescaler(uint8_t constant, uintmax_t prescaler, uintmax_t clockSource = F_CPU) : Enum<uint8_t>(constant), prescaler(prescaler), clockSource(clockSource)
	{

	}
	uintmax_t prescaler;
	uintmax_t clockSource;
};


#endif /* ENUM_H_ */
